﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FlowgraphViewer.Model;
using System.Linq;

namespace FlowgraphViewer.Services.Parsers
{
    public class FlowNodeParser
    {
        public static FlowNode Parse(string s)
        {
            var result = NodeService.Instance.Nodes.Where((node) => node.Name.ToLower().Equals(s.ToLower()));

            if (result.Count() <= 0)
            {
                // Sometimes there is no Misc: in front
                result = NodeService.Instance.Nodes.Where(node => node.Name.ToLower().Equals("misc:" + s.ToLower()));

                if (result.Count() <= 0)
                    throw new Exception(String.Format("{0} node not found", s));
            }
            return result.First();
        }
    }
}
